<?php // echo par($crosstab); ?>
<?php //echo par(array_values($crosstab->columns)); ?>

<style type="text/css">
<!--
table.crosstab
{
    width: 0;
}
table.crosstab thead th, tbody td
{
    white-space: nowrap;
}
table.crosstab tbody td.first
{
    font-weight: bold;
}
-->
</style>
<table <?php echo isset($htmlOptions['cssClass']) ? $htmlOptions['cssClass'] : 'class="crosstab"' ?> id="<?php echo $crosstabId ?>">
    <thead>
        <tr>
            <th><?php echo CHtml::encode($crosstab->labels->cells); ?></th>
            <th colspan="<?php echo count($crosstab->columns); ?>"><?php echo $crosstab->labels->column; ?></th>
        </tr>
        <tr>
            <th><?php echo CHtml::encode($crosstab->labels->row); ?></th>
            <?php foreach($crosstab->columns as $column) : ?>
            <th><?php echo CHtml::encode($column); ?></th>
            <?php endforeach; ?>
        </tr>
    </thead>
    <tbody>
        <?php $nRows = 0; foreach($crosstab->rows as $row=>$columns) : ?>
        <tr class="<?php echo $nRows++%2 ? 'even' : 'odd'; ?>">
            <td class="first"><?php echo CHtml::encode($row); ?></td>
            <?php foreach($columns as $columnValue=>$cells) : ?>
            <?php if(!is_array($cells)) { echo '<td></td>'; continue; } ?>
            <td>
                <?php foreach($cells as $cell) : ?>
                <?php if(is_null($crosstab->cellsLink)) : ?>
                <?php echo CHtml::encode($cell); ?>
                <?php else : ?>
<?php
if(is_array($crosstab->cellsLink)) {
    $route = $crosstab->cellsLink[0];
    $paramsString = '';
    if(count($crosstab->cellsLink)>1) {
        $params = $crosstab->cellsLink;
        unset($params[0]);
        // DEBUG echo par($params);
        foreach($params as $key=>$value) {
            $paramsString .= ", '$key'=>'$value'";            
        }
    }
} else {
    $route = $crosstab->cellsLink;
    $paramsString = '';
}
?>
                <?php eval("\$link = CHtml::link(CHtml::encode('".$cell."'), array('$route','row'=>'$row', 'column'=>'$columnValue'$paramsString));"); echo $link; ?>
                <?php endif; ?>
                <?php endforeach; ?>
            </td>
            <?php endforeach; ?>
        </tr>
        <?php endforeach; ?>
    </tbody>
</table>
